/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import manager.accountManager;
import model.admin.Accounts;

/**
 *
 * @author Danh
 */
@ManagedBean
@SessionScoped
public class Accountbean implements Serializable {

    private int accountId;
    private String username;
    private String password;
    private String email;
    private boolean status;
    private String role;

    public String editAccount(int id, String username, String password, String email, boolean status, String role) {
        this.accountId = id;
        this.username = username;
        this.password = password;
        this.email = email;
        this.status = status;
        this.role = role;
        return "updateAccount.xhtml?faces-redirect=true";
    }

    public int getAccountId() {
        return accountId;
    }

    public void setAccountId(int accountId) {
        this.accountId = accountId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }
    private List<Accounts> list;
//    private String 

    public List<Accounts> getList() {
        return list;
    }

    public void setList(List<Accounts> list) {
        this.list = list;
    }

    public Accountbean() {
    }

    public Accountbean(int accountId, String username, String password, String email, boolean status, String role) {
        this.accountId = accountId;
        this.username = username;
        this.password = password;
        this.email = email;
        this.status = status;
        this.role = role;
    }

    public List<Accounts> loadAccount() {
        accountManager mana = new accountManager();
        list = mana.getall();
        return list;
    }

    public String accountDetail(int id) {
        
        return null;
    }

    public void updateAccount(ActionEvent e) {

        Accounts ac = (Accounts) e.getComponent().getAttributes().get("account");

        accountManager mana = new accountManager();
        boolean result = mana.update(ac);

        if (result) {

            loadAccount();
        }
    }
}
